package com.seventh.parkingrent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seventh.parkingrent.domain.User;
import com.seventh.parkingrent.dao.UserMapper;
import com.seventh.parkingrent.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public Integer getNeedAuditUserNo() {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("isaudit","0");
        wrapper.eq("state","1");
        List<User> users = userMapper.selectList(wrapper);
        if(null==users){
            return 0;
        }
        return users.size();
    }

    @Override
    public IPage<User> getNeedAuditUser(Integer pageIndex,Integer pageSize) {
        IPage<User> page = new Page(pageIndex,pageSize);
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("isaudit","0");
        wrapper.eq("state","1");
        IPage<User> users = userMapper.selectPage(page,wrapper);
        return users;
    }

    @Override
    public Integer updateUserAudit(Integer userId, String isaudit) {

        User user = userMapper.selectById(userId);
        user.setIsaudit(isaudit);
        int i = userMapper.updateById(user);
        return i;
    }

    @Override
    public User selectUserById(Integer userId) {
        User user = userMapper.selectById(userId);
        return user;
    }

    @Override
    public List<String> selectUsername() {

        List<String> usernames = userMapper.selectUsername();
        return usernames;
    }


}
